﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GameEngine.View.Components;

namespace GameEngine.Clients.Silverlight.View.Components
{
    public partial class WorldUC : UserControl, IWorldView<int, FrameworkElement>
    {
        MapUC Map;

        public WorldUC()
        {
            InitializeComponent();
            this.SizeChanged += new SizeChangedEventHandler(WorldUC_SizeChanged);
        }

        void WorldUC_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (Map != null) {
                Map.ViewSize = new Point(ActualWidth, ActualHeight);
            }
        }

        public Point TileSize
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public float MaxMapHeight
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public float MinMapHeight
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public float TileHeightUnit
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public void SetMapView(IMapView<int,FrameworkElement> map)
        {
            Map = map as MapUC;
            LayoutCanvas.Children.Add(map as UIElement);
            //map.ViewSize = new Point(LayoutCanvas.ActualWidth, LayoutCanvas.ActualHeight);
        }

        public void AddUIElement(IThingView<int, FrameworkElement> p, Point point, float p_3)
        {
            Map.AddUIElement(p as ItemUC, point, p_3);
            //LayoutCanvas.Children.Add(p);
        }

        public void UpdateUIElement(IThingView<int, FrameworkElement> p, Point point, float p_3)
        {
            Map.UpdateUIElement(p as ItemUC, point, p_3);
        }

        public void RemoveUIElement(IThingView<int, FrameworkElement> p)
        {
            Map.RemoveUIElement(p as ItemUC);
            //LayoutCanvas.Children.Remove(p);
        }

        public event Action<Point> MyOnSizeChanged;

        public event ItemMouseButtonEventDelegate<IThingView<int, FrameworkElement>> ItemMouseLeftButtonUp;

        /*public void AddElement(ItemUC uiElement, MapEngine.Point3d position, MapEngine.Point3d rotation)
        {
            throw new NotImplementedException();
        }*/

        public void UpdateMapPosition()
        {
            Map.UpdateMapPosition();
        }
    }
}
